package com.sylli.oeuf.server.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Tool {
	
	public static byte[] createByteArrayFromObject(Serializable o) throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oos;
		oos = new ObjectOutputStream(baos);
		oos.writeObject(o);
		oos.close();
		return baos.toByteArray();
	}
	
	public static Object createObjectFromByteArray(byte[] byteObject) throws IOException, ClassNotFoundException {
		ByteArrayInputStream bais;
		ObjectInputStream ois;
		bais = new ByteArrayInputStream(byteObject);
		ois = new ObjectInputStream(bais);
		return ois.readObject();
		
	}
}
